function delay(fn, delayTime) {
    return Promise.resolve({
        then: function (resolve, reject) {
            setTimeout(function () {
                if (fn) {
                    resolve(fn());
                } else {
                    resolve();
                }
            }, delayTime);
        }
    })

    // return new Promise(function(resolve,reject){
    //     setTimeout(function() {
    //         resolve(fn());
    //     }, delayTime);
    // })
}

var promise1 = delay(function () {
    console.log("time done");
    return "ok";
}, 100);
var promise2 = delay(function () {
    console.log("second promise");
    return "second ok";
}, 200)
var promise3 = Promise.reject("error");
// 门：promise.all([]);
//有一个失败，则所有都失败，则不会再等待其他的结果
//所有都成功，则为成功
//promise.all([])数组中可以使一个立即值，可以使promise，可以使thenable
Promise.all([promise1, promise2, 43, { then: function (resolve, reject) { resolve(24) } }]).then(
    function (value) {
        console.log(value);
    },
    function onRejected(value) {
        console.log("error:" + value);
    }
)